<?php
	// ----------------------------------------------------
	// Beschreibung Skript:
	//   Gibt den aktuellen Benutzer aus und speichert
	//   Änderungen an diesem Benutzer.
	//
	// ----------------------------------------------------
	// Änderungen:
	//
	// ----------------------------------------------------
	
	
	// ------------------------------------------------------
	// Initialisiert das Skript.
	// ------------------------------------------------------
	require_once 'loader.php';

	// ------------------------------------------------------
	// Verarbeitet POST Daten.
	// ------------------------------------------------------
	$ExterUserID = 'andy';
	if(isset($_POST['ExternalUserID'])) {
		$ExterUserID = htmlspecialchars($_POST['ExternalUserID']);
	}
	$Member->getUserData($ExterUserID);
	
	// ------------------------------------------------------
	// Header laden.
	// ------------------------------------------------------
	$Header->printHeader();
	
	// ------------------------------------------------------
	// Memberdata laden.
	// ------------------------------------------------------
	// Print committee, job and License data.
	$arrLabel = Array('Familienflag',
					  'Lizenzen', 'User-Status', 'Aufgaben', 'Vorstand');
	$arrValue = Array($Member->MemberState, $Member->FamilyFlag?'Ja':'Nein',
	$Member->Associations->getAssociationsAsString(), $Member->State?'Aktiv':'Inaktiv', $Member->Jobs->getJobsAsString(), $Member->CommitteeTasks->getCommitteeTasksAsString());
	$arrMemberStates = $UserDb->getMemberStates();
	$arrAssociationTypes = $UserDb->getAssociationTypes();
	$arrJobTypes = $UserDb->getJobTypes();
	$arrCommitteeTaskTypes = $UserDb->getCommitteeTaskTypes();
	//
	print('<form Action="get_user.php" method="post">'."\n");
	print('<input type="hidden" name="ExternalUserID" value="'.$ExterUserID.'">'."\n");
	print('<input type="hidden" name="Action" value="setMemberData">'."\n");
	print('<table>'."\n");
	print('  <tbody>'."\n");
	
	// Name, Firstname:
	print('    <tr>'."\n");
	print('      <td width="120">&nbsp;</td>'."\n");
	print('      <td width="150">Vorname, Name:</td>'."\n");
	print('      <td width="150" class="name">'.$Member->FirstName.' '.$Member->LastName.'</td>'."\n");
	print('    </tr>'."\n");
	
	// MemberState:
	print('    <tr>'."\n");
	print('      <td width="120">&nbsp;</td>'."\n");
	print('      <td width="150">Mitgliederstatus:</td>'."\n");
	print('      <td width="150" class="memberstate"><select name="MemberState" size="1">'."\n");
	foreach ($arrMemberStates as $key=>$value) {
		if ($Member->MemberState == $value) {
			print('      <option value="'.$key.'-'.$value.'" selected="selected">'. $value .'</option>'."\n");
		} else {
			print('      <option value="'.$key.'-'.$value.'">'. $value .'</option>'."\n");
		}
	}
	print('      </select></td>'."\n");
	print('    </tr>'."\n");
	
	// FamilyFlag:
	print('    <tr>'."\n");
	print('      <td width="120">&nbsp;</td>'."\n");
	print('      <td width="150">Familienflag:</td>'."\n");
	print('      <td width="150" class="familyflag"><select name="FamilyFlag" size="1">'."\n");
	if ($Member->FamilyFlag) {
		print('      <option value="1" selected="selected">Ja</option>'."\n");
		print('      <option value="0">Nein</option>'."\n");
	} else {
		print('      <option value="1">Ja</option>'."\n");
		print('      <option value="0" selected="selected">Nein</option>'."\n");
	}
	print('      </select></td>'."\n");
	print('    </tr>'."\n");
	
	// Licenses:
	print('    <tr>'."\n");
	print('      <td width="120">&nbsp;</td>'."\n");
	print('      <td width="150" valign="top">Lizenzen:</td>'."\n");
	print('      <td width="150" class="license">'."\n");
	foreach ($arrAssociationTypes as $key=>$value) {
		if (isset($Member->Associations->AssociationList[$value])) {
			print('      <div>'."\n");
			print('        <span><input type="checkbox" name="AssociationTypes[]" value="'.$value.'" checked="checked">'. $value .'</span>'."\n");
			print('        <input name="'.strtolower($value).'_license" type="text" size="10" maxlength="10" value="'.$Member->Associations->AssociationList[$value].'"'."\n");
			print('      </div>'."\n");
		} else { 
			print('      <div>'."\n");
			print('        <span style="display: inline-block; width: 60px;"><input type="checkbox" name="AssociationTypes[]" value="'.$value.'">'. $value .'</span>'."\n");
			print('        <input name="'.strtolower($value).'_license" type="text" size="10" maxlength="10"'."\n");
			print('      </div>'."\n");
								}
	}
	print('      </td>'."\n");
	print('    </tr>'."\n");

	// Jobs:
	print('    <tr>'."\n");
	print('      <td width="120">&nbsp;</td>'."\n");
	print('      <td width="150" valign="top">Aufgaben:</td>'."\n");
	print('      <td width="150" class="jobs">'."\n");
	foreach ($arrJobTypes as $key=>$value) {
		if (strpos($Member->Jobs->getJobsAsString(), $value) === false) {
			print('      <input type="checkbox" name="Jobs[]" value="'.$key.'-'.$value.'">'. $value .'<br />'."\n");
		} else {
			print('      <input type="checkbox" name="Jobs[]" value="'.$key.'-'.$value.'" checked="checked">'. $value .'<br />'."\n");
		}
	}
	print('      </td>'."\n");
	print('    </tr>'."\n");
	
	// CommitteeTasks:
	print('    <tr>'."\n");
	print('      <td width="120">&nbsp;</td>'."\n");
	print('      <td width="150" valign="top">Vorstand:</td>'."\n");
	print('      <td width="150" class="committeetask">'."\n");
	foreach ($arrCommitteeTaskTypes as $key=>$value) {
		if (strpos($Member->CommitteeTasks->getCommitteeTasksAsString(), $value) === false) {
			print('      <input type="checkbox" name="CommitteeTasks[]" value="'.$key.'-'.$value.'">'. $value .'<br />'."\n");
		} else { 
			print('      <input type="checkbox" name="CommitteeTasks[]" value="'.$key.'-'.$value.'" checked="checked">'. $value .'<br />'."\n");
		}
	}
	print('      </td>'."\n");
	print('    </tr>'."\n");

	// User-State:
	print('    <tr>'."\n");
	print('      <td width="120">&nbsp;</td>'."\n");
	print('      <td width="150">User-Status:</td>'."\n");
	print('      <td width="150" class="userstate"><select name="State" size="1">'."\n");
	if ($Member->State) {
		print('      <option value="1" selected="selected">Aktiv</option>'."\n");
		print('      <option value="0">Inaktiv</option>'."\n");
	} else {
		print('      <option value="1">Aktiv</option>'."\n");
		print('      <option value="0" selected="selected">Inaktiv</option>'."\n");
	}
	print('      </select></td>'."\n");
	print('    </tr>'."\n");

	print('    <tr>'."\n");
	print('      <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>'."\n");
	print('    </tr>'."\n");
	
	print('    <tr>'."\n");
	print('      <td>&nbsp;</td><td>&nbsp;</td><td align="right">'."\n");
	print('      	<input type="button" value="Abbrechen" onclick="location.href = \'get_user.php\'">'."\n");
	print('      	<span style="width:10pt;">&nbsp;</span>'."\n");
	print('      	<input type="submit" value="Senden">'."\n");
	print('      </td>'."\n");
	print('    </tr>'."\n");
	print('  </tbody>'."\n");
	print('</table>'."\n");
	print('</form>'."\n");

	// ------------------------------------------------------
	// Footer laden.
	// ------------------------------------------------------
	include 'footer.php';
?>